package com.mzx.admin.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mzx.admin.service.AdminService;
import com.mzx.entity.Admin;
import com.mzx.entity.BaseDict;
import com.mzx.entity.Info;

@Controller
@RequestMapping("/Admin")
public class AdminController {
@Autowired
private AdminService adminService;
			/*管理员登陆控制器*/
@PostMapping("/login.action")
public String login(Admin admin,HttpSession httpSession,Model model) {
admin =adminService.login(admin);
	
	if(admin==null) {
		model.addAttribute("msg", "用户不存在 请重新输入！");
		return "admlogin";
		}
		httpSession.setAttribute("admin",admin);
		return "forward:/Admin/loadinfo.action";
	
}
			/*跳转登录*/
@GetMapping("/GotoLogin.action")
public String GotoLogin() {
	
	return "admlogin";
}
			/*加载下拉列表*/
@RequestMapping("/loadinfo.action")
public String loadinfo(HttpSession session) {
	
	List<BaseDict> state = adminService.LoadInfo("004");
	

	session.setAttribute("state", state);
	
	return "forward:/Admin/infos.action";

}
			/*加载所有维修信息*/
@RequestMapping("/infos.action")
public String getInfos(Model model,Info info) {
	List<Info> infos=adminService.getInfos();
	System.out.println(infos);
	model.addAttribute("infos",infos);
	return "home-admin";
	
}
			/*维修状态修改*/
@RequestMapping("changeInfo.action")
@ResponseBody
public Boolean changeInfo(Info info) {
	System.out.println(info);
	Date date = new Date();
	info.setInfo_createtime(date);
	return adminService.changeInfo(info);
	
	
}
}
